package com.odobenus.client.hock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.odobenus.client.properties.OdobenusProperties;
import com.odobenus.client.zk.ZooKeeperServiceRegistry;
public class StartListener implements ApplicationListener<ContextRefreshedEvent> {
    private Logger logger = LoggerFactory.getLogger(getClass());
    
    private ZooKeeperServiceRegistry zooKeeperServiceRegistry;
    private OdobenusProperties odobenusProperties;
    
    public StartListener(ZooKeeperServiceRegistry zooKeeperServiceRegistry, OdobenusProperties odobenusProperties) {
		super();
		this.zooKeeperServiceRegistry = zooKeeperServiceRegistry;
		this.odobenusProperties = odobenusProperties;
	}

	@Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        logger.info("程序启动");
        if (odobenusProperties.getEnableRemote()) {
			zooKeeperServiceRegistry.register(odobenusProperties.getApplicationName(), odobenusProperties.getApplicationDomain());
		}
    }

}